package com.ljm.sys.auth.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import com.ljm.sys.auth.dto.UserRefDto;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.ljm.sys.auth.api.SysAuthUserRoleApi;
import com.ljm.sys.auth.dto.SysAuthUserRoleDto;

import org.springframework.stereotype.Controller;

/**
 * <p>
    * 系统用户角色关联 前端控制器
    * </p>
 *
 * @author HuamingChen
 * @since 2020-06-11
 */
@Api("系统用户角色关联")
@Controller
@RequestMapping("/auth/sysAuthRole/sysAuthUserRole")
public class SysAuthUserRoleController {

    /**
    * 系统用户角色关联接口
    */
    @Resource
    private SysAuthUserRoleApi iSysAuthUserRoleApi;

    @ApiOperation(value="指派用户")
    @RequestMapping(value = "/setUserRoleRef",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult setUserRoleRef(@RequestBody UserRefDto dto){
        iSysAuthUserRoleApi.setUserRoleRef(dto);
        return ResultUtil.success();
    }

    @ApiOperation(value="取消指派")
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult del(@ApiParam(value="主键") @RequestBody List<Long> ids){
        iSysAuthUserRoleApi.delRoleRefUser(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value="分页获取系统用户角色关联")
    @RequestMapping(value = "/getByPage",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult getByPage(@ApiParam(value="名称") @RequestParam(required = false) String realName,
                                @ApiParam(value="角色代码") @RequestParam(required = false) String roleCode,
                                @ApiParam(value="账号") @RequestParam(required = false) String loginName,
                                @ApiParam(value="邮箱") @RequestParam(required = false) String email,
                                @ApiParam(value="页码") @RequestParam(defaultValue = "1") Integer pageNo,
                                @ApiParam(value="页大小") @RequestParam(defaultValue = "10") Integer pageSize){
        return ResultUtil.successData(iSysAuthUserRoleApi.getRoleRefUser(realName,roleCode,loginName,email,pageNo,pageSize));
    }
}
